<?php

namespace app\admin\model\chat;

use think\Model;


class Room extends Model
{

    

    

    // 表名
    protected $name = 'chat_room';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'information_id_text',
        'is_margin_text',
        'group_type_text',
        'type_text',
        'last_time_text',
        'add_time_text'
    ];
    

    
    public function getInformationIdList()
    {
        return ['1' => __('Information_id 1'), '0' => __('Information_id 0'), 'P' => __('Information_id p')];
    }

    public function getIsMarginList()
    {
        return ['1' => __('Is_margin 1'), '2' => __('Is_margin 2')];
    }

    public function getGroupTypeList()
    {
        return ['1' => __('Group_type 1'), '2' => __('Group_type 2')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
    }


    public function getInformationIdTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['information_id']) ? $data['information_id'] : '');
        $list = $this->getInformationIdList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsMarginTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_margin']) ? $data['is_margin'] : '');
        $list = $this->getIsMarginList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGroupTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['group_type']) ? $data['group_type'] : '');
        $list = $this->getGroupTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLastTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['last_time']) ? $data['last_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setLastTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAddTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'user_id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'to_id', 'user_id', [], 'LEFT')->setEagerlyType(0);
    }
}
